package com.xm.xmapp.adapter;

import java.util.ArrayList;

import android.app.Activity;
import android.graphics.Color;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.xm.xmapp.R;
import com.xm.xmapp.base.MyBaseAdapter;
import com.xm.xmapp.base.ViewHolder;
import com.xm.xmapp.myinterface.PinJiaInterFace;
import com.xm.xmapp.response.bean.OrderBeanResponse;
import com.xm.xmapp.tools.StringTools;

public class LongRentOrderListAdapter extends MyBaseAdapter<OrderBeanResponse> {

	public LongRentOrderListAdapter(ArrayList<OrderBeanResponse> list, Activity context, int layoutId) {
		super(list, context, layoutId);
	}

	private PinJiaInterFace interFace;

	public PinJiaInterFace getInterFace() {
		return interFace;
	}

	public void setInterFace(PinJiaInterFace interFace) {
		this.interFace = interFace;
	}

	@Override
	public void setValues(ViewHolder holder, final OrderBeanResponse t, final int position) {

		holder.setText(R.id.name, t.car_number)
				.setText(R.id.address, StringTools.getTime(t.add_time * 1000, "yyyy-MM-dd HH:mm:ss"))
				.setText(R.id.qidian, StringTools.getTime(t.add_time * 1000, "yyyy-MM-dd"))
				.setText(R.id.zhongdian, StringTools.getLongTime(t.long_rent_repay_date));
		holder.setText(R.id.pay, t.pay_money + "元");
		// status--
		// `order_status` tinyint(1) DEFAULT '1' COMMENT
		// '订单状态：1=已下单，2=租赁中，3=已还车,4=已取消，5=锁定（不支持操作）',
		TextView status = (TextView) holder.getView(R.id.status);
		status.setBackgroundDrawable(null);
		status.setTextColor(ContextCompat.getColor(activity, R.color.color6));

		switch (t.order_status) {
		case "1":
			status.setText("已下单");
			status.setOnClickListener(null);
			status.setTextColor(ContextCompat.getColor(activity, R.color.color6));
			status.setBackgroundDrawable(null);
			break;
		case "2":
			status.setOnClickListener(null);
			status.setText("续用");
			status.setTextColor(ContextCompat.getColor(activity, R.color.white));
			status.setBackgroundColor(Color.parseColor("#FF8000"));
			status.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {

					if (interFace != null) {
						interFace.setTextView(v, position);
					}
				}
			});
			break;
		case "3":
			status.setText("已还车");
			if (!t.is_comment.equals("1")) {
				status.setText("去评价");
				status.setTextColor(ContextCompat.getColor(activity, R.color.huangse));
				status.setBackgroundResource(R.mipmap.dingdan_pingjia_btn);
				status.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						if (interFace != null) {
							interFace.setTextView(v, position);
						}
					}
				});

			} else {
				status.setOnClickListener(null);
				status.setTextColor(ContextCompat.getColor(activity, R.color.color6));
				status.setBackgroundDrawable(null);
			}
			break;
		case "4":
			status.setText("已取消");
			status.setOnClickListener(null);
			status.setTextColor(ContextCompat.getColor(activity, R.color.color6));
			status.setBackgroundDrawable(null);
			break;

		case "5":
			status.setText("锁单");
			status.setOnClickListener(null);
			status.setTextColor(ContextCompat.getColor(activity, R.color.color6));
			status.setBackgroundDrawable(null);
			break;
		default:
			status.setText("锁单");
			status.setOnClickListener(null);
			status.setTextColor(ContextCompat.getColor(activity, R.color.color6));
			status.setBackgroundDrawable(null);
			break;
		}

		holder.getConvertView().setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				in.DoSomeThing(t);
			}
		});

	}

}
